package com.zzq.springboot1.config;

import org.omg.PortableInterceptor.Interceptor;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class LoginHanderInterceptor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        //获得一个session值
        Object loginUser = request.getSession().getAttribute("LoginUser");
        //业务处理
        if(loginUser==null){//没有登录
            request.setAttribute("msg","没有权限请登录");
            request.getRequestDispatcher("/").forward(request,response);
            return false;

        }else {
            return true;
        }
    }


}
